package cn.edu.sdu.sduhour.mapper;

import cn.edu.sdu.sduhour.entity.Achivements;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AchivementsMapper {
    //获取所有成就
    @Select("select * from achivements where openid=#{openid}")
    List<Achivements> findAll(Achivements achivements);

    //获取所有显性成就
    @Select("SELECT light,spring,defender,morning,wind,justice FROM `achivements` where openid=#{openid}")
    List<Achivements> findDominant(Achivements achivements);

    //获取所有隐性成就
    @Select("SELECT careless,thunder FROM `achivements` where openid=#{openid}")
    List<Achivements> findRecessive(Achivements achivements);

    //新增一条成就记录（新增用户时使用）
    @Update("INSERT INTO `sduhour`.`achivements` (`openid`, `light`, `spring`, `defender`, `morning`, `wind`, `justice`, `careless`, `thunder`) VALUES (#{openid}, 0, 0, 0, 0, 0, 0, 0, 0)")
    void addOne(Achivements achivements);

    //删除一条成就记录（管理员）
    @Delete("DELETE FROM `achivements` WHERE `id` = #{id}")
    void delOne(Achivements achivements);

    //变更成就
    @Update("UPDATE `sduhour`.`achivements` SET ${changeName}=1 WHERE openid=#{openid}")
    void changeOne(Achivements achivements);
}
